<!-- 出库(仓库端或货主端)、出库复核(货主端)、提交签收(承运商)、签收复核(货主端) -->
<template>
  <div class="border border-solid border-black p-[10px] pb-[0] my-[20px] flex">
    <div>签收单上传：</div>
    <BasicUploadImage :params="params" :fileLists="fileList" />
  </div>
  <div class="mb-[20px]">
    补充说明：
    <Textarea class="w-[100%]" :rows="5" disabled v-model:value="formState.remark" />
  </div>
  <div class="p-[10px] bg-[#99f599]">
    <p class="mb-[20px]">审核提示:</p>
    <div class="ml-[10px]">
      <p class="mb-[20px]">1.司机务必现场拍照(出库单、出仓单)上传附件</p>
      <p class="mb-[20px]">2.上传单据必须要有仓管和司机两人的签名</p>
      <p class="mb-[20px]">3.单据上必须备注货物牌号、数量、签收出库量、是否破损及额外收费等情况</p>
    </div>
  </div>
</template>
<script lang="ts" setup>
  import { ref, defineEmits } from 'vue';
  import { message, Textarea } from 'ant-design-vue';
  import BasicUploadImage from '@/components/UploadImage/BasicUploadImage.vue';
  import { postSignRecheck } from '@/api/waybillManagement/index';

  import { getUserFiles } from '@/api/common';

  const emit = defineEmits(['onSuccess', 'onFailed']);

  const params = ref({
    configCode: 'eslogis_order',
    label: 'signCheck',
    batchId: '',
  });
  const fileList = ref([]);

  const formState = ref({
    shippingOrderId: 0,
    fileLabel: '',
    remark: '',
  });

  // const changeFileRes = async (data: any) => {
  //   fileList.value.push(data);
  // };

  const initFormState = async (queryParams) => {
    console.log('🚀 ~ initFormState ~ queryParams:', queryParams);
    params.value.batchId = queryParams.batchId;
    formState.value = {
      shippingOrderId: queryParams.shippingOrderId,
      fileLabel: queryParams.fileLabel,
      remark: queryParams.remark,
    };

    const res = await getUserFiles({
      ...params.value,
      label: 'sign',
    });
    fileList.value = res;
  };

  const Commit = async () => {
    try {
      await postSignRecheck({
        ...formState.value,
        isPass: true,
      });
      message.success('处理成功');
      emit('onSuccess');
    } catch (error) {
      emit('onFailed');
      message.error(error.message);
    }
  };

  const Return = async (rejectRemark) => {
    try {
      await postSignRecheck({
        ...formState.value,
        rejectRemark,
        isPass: false,
      });
      message.success('处理成功');
      emit('onSuccess');
    } catch (error) {
      message.error(error.message);
      emit('onFailed');
    }
  };

  defineExpose({
    initFormState,
    Commit,
    Return,
  });
</script>
